const db = require('../../database')
const writeLogs = require('./writeLogs');

module.exports = (req, res) => {
    const username = req.auth.username;
    const sql = 'delete from users where username = ?';
    db.query(sql, username, (err, data) => {
        if (err) return res.cc(err)
        if (data.affectedRows === 0) return res.cc('注销失败，用户不存在');
        writeLogs('logoff', {username});
        res.cc('注销成功', 0);
    })
}